﻿#ifndef LINEEDITNUM_H
#define LINEEDITNUM_H

#include <QWidget>
#include "LineEdit.h"
#include "ui_base_lib_global.h"
enum LineEditNumType{
    LINEEDIT_TYPE_DB_ONE,        
    LINEEDIT_TYPE_HZ_ONE,        
    LINEEDIT_TYPE_Q_TWO,        
    LINEEDIT_TYPE_DB,           
    LINEEDIT_TYPE_HZ,         
};
typedef struct tagSliderGroupInfo
{
    QString strUnit;
    float max;
    float min;
    float current;
    float step;
    int precision;
    float calibration;
    float multiple;

    bool m_flag = false;
    QString strMax;
    QString strMin;

    bool  isConstraint  = false;
    float maxConstraint;
    float minConstraint;

    bool  isProgress  = false;
    QColor colorProgress;

    bool isAbbr = false;
}SliderGroupInfo;

#define UI_LINEEDITNUM_ID 0x1102
class UI_BASE_LIBSHARED_EXPORT LineEditNum : public LineEdit
{
    Q_OBJECT
public:
    explicit LineEditNum(QWidget *parent = nullptr);
    static void initLineEdit(LineEditNum* p , int x , int y , int w , int h , QString style , SliderGroupInfo info);

    void setRange(float max,float min);
    float getCurrentValue();

    void setPrecision(int i);

    void setStep(float value);

    void setCurrentRealValue(float value);
    float getCurrentRealValue();

    void setConstraintRange(float min , float max);
    void setConstraintRangeMin(float min);
    void setConstraintRangeMax(float max);

protected:
    void addValue();
    void subValue();
    void changeText(float &value);

    void inspectValue(float &value);

    int m_precision;

    float m_step;

    QString m_strUnit;

    float m_value;

    float m_max;

    float m_min;

    float m_calibration;
    float m_multiple;

    bool m_isAbbr;

    bool  m_isConstraint;
    float m_maxConstraint;
    float m_minConstraint;

    bool m_flag;
    QString m_strMax;
    QString m_strMin;

protected:
    virtual void keyPressEvent(QKeyEvent *);
    virtual void wheelEvent(QWheelEvent *event);
    virtual void focusOutEvent(QFocusEvent *);
    virtual void focusInEvent(QFocusEvent *);
signals:

    void evt_itemActivate(bool flag);
public slots:

    void on_updateUi(float value);

    void on_TextEdit(const QString &str);

    void on_Enter();
};

#endif 
